package cn.tedu.spring.di;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * 注入对象类型的数据
 *
 */
@Service
public class UserService {
    @Value("上帝业务")
    private String name;
    /**
     * @Autowired :
     * 1.对象类型依赖注入的注解
     * 2.添加位置
     *  2.1 属性注入，添加在属性上
     *  2.2 set方法注入，添加在set方法上
     *  2.3 构造方法注入，添加在构造方法上
     */

    @Autowired //属性注入
    private UserDao userDao;

    @Autowired //构造方法注入
    public UserService(UserDao userDao) {
        this.userDao = userDao;
    }

    @Autowired  //方法注入
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }



    @Override
    public String toString() {
        return "UserService{" +
                "name='" + name + '\'' +
                ", userDao=" + userDao +
                '}';
    }
}
